<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>竞品情报</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css" />
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<input type="hidden" name="companyName" id="companyName" th:value="${companyName}">
<div class="container-fluid">
    <div class="row" th:class="text-center" style="margin-top: 50px;margin-bottom: 20px;">
        <h2>竞品情报</h2>
    </div>
    <div th:class="card" th:id="card"></div>
<!--    <div class="card" th:each="item:${pageobj.records}">-->
<!--        <div class="card-body">-->
<!--            <h5 class="card-title" th:if="${item.title eq null}" th:text="${item.source}" />-->
<!--            <h5 class="card-title" th:if="${item.title ne null}" th:text="${item.title}" />-->
<!--            <p class="card-text" th:if="${item.content ne null}" th:utext="${item.content}"/>-->
<!--            <span class="text-muted" th:text="${item.newsDate}" />&nbsp;&nbsp;&nbsp;-->
<!--            <span class="text-muted" th:text="${item.shortName}"/>&nbsp;&nbsp;&nbsp;-->
<!--            <span class="text-muted" th:if="${item.tags ne null and item.tags ne ''}" th:text="${item.tags}" />&nbsp;&nbsp;&nbsp;-->
<!--            <a th:href="${item.sourceUrl}" class="card-link" target="_blank">预览>></a>-->
<!--        </div>-->
<!--    </div>-->
    <div class="row" th:class="text-center" style="margin-top: 50px;margin-bottom: 20px;">
        <button type="button" id="jzgd" class="btn btn-default">加载更多</button>
    </div>
</div>
</body>

<script type="text/javascript">

    var page = 1;
    var pagesize = 20;
    var companyName = $("#companyName").val();
    loadData(page, pagesize);

    $(function(){
       $("#jzgd").click(function(){
            page ++;
            loadData(page, pagesize);
       });
    });

    function loadData(page, pagesize) {
        $.ajax({
           url:"/custom/core/news/pageAjax?curPage="+page+"&pagesize=" + pagesize + "&companyName=" + companyName,
            type:"json",
            method:"post",
            async:false,
            success:function(resp) {
                console.log(resp)
                var list = resp.records;
                for (var i = 0; i < list.length; i++) {
                    var item = list[i];
                    var title = item.title;
                    if (title == null) {
                        title = item.source;
                    }
                    var content = item.content;
                    var newsDate = item.newsDate;
                    var shortName = item.shortName;
                    var tags = item.tags;
                    var sourceUrl = item.sourceUrl;
                    var html = '<div class="card-body">'
                    html += '<h5 class="card-title">' + title + '</h5>';
                    if (content) {
                        html += '<p class="card-text">' + content + '</p>';
                    }
                    html += '<span class="text-muted">' + newsDate + '</span>&nbsp;&nbsp;&nbsp;';
                    html += '<span class="text-muted">' + shortName + '</span>&nbsp;&nbsp;&nbsp;';
                    if (tags) {
                        html += '<span class="text-muted">' + tags + '</span>&nbsp;&nbsp;&nbsp;';
                    }
                    html += '<a href="/custom/core/news/article_detail?id=' + item.id + '" class="card-link" target="_blank">预览>></a>';
                    html += '</div>'
                    $("#card").append(html);
                }
            }
        });
    }

</script>
</html>